from selenium.webdriver.common.by import By

from base_page import BasePage

# diver.find_element_by_xpath('//*[@id="emp_DomainName"]').send_keys("zqchud")
# diver.find_element_by_xpath('//*[@id="emp_Password"]').send_keys("H@andsome835422")
# diver.find_element_by_xpath('//*[@id="BtnLogin"]').click()

class LoginPage(BasePage):
    _username = (By.XPATH, '//*[@id="emp_DomainName"]')
    _password = (By.XPATH, '//*[@id="emp_Password"]')
    _submit = (By.XPATH, '//*[@id="BtnLogin"]')
    _error_msg = (By.XPATH, '//*[@id="Submit"]/span')
    _succuss_msg=(By.XPATH,"//*[@id='g_logout']")


    def login_successfully(self, username, password):
        self.find_element_and_input(self._username, username)
        self.find_element_and_input(self._password, password)
        self.find_element_and_click(self._submit)
        # return MainPage(self.driver)
        return self

    # 账号或者密码错误
    def login_failed(self, username, password):
        self.find_element_and_input(self._username, username)
        self.find_element_and_input(self._password, password)
        self.find_element_and_click(self._submit)
        return self

    # 账号密码为空
    def login_empty(self):
        self.find_element_and_click(self._submit)
        return self
    def get_log_error_msg(self):
        return self.get_element_attribute(self._error_msg,"textContent")

    def get_successmsg(self):
        return self.get_element_attribute(self._succuss_msg, "textContent")


